package siam.ui;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;

import javax.swing.JPanel;
import java.awt.Color;
import java.awt.GridLayout;

@SuppressWarnings("serial")
public class SiamPanel extends JPanel {

	/**
	 * Caracterize board (N * N) elements
	 */
	private final int NUMBER_PIECES = 5;
	/**
	 * Represent the board
	 */
	private SiamCase[][] board= new SiamCase[NUMBER_PIECES][NUMBER_PIECES];
	private SiamInformation siamInformation;
	private ForcePanel forcePanel;
	
	public SiamPanel() {
		initLayout();
		init();
	}
	/**
	 * Init the Layout
	 * {@link GridBagLayout}
	 */
	private void initLayout() {
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{0, 0, 0, 0, 0, 0};
		gridBagLayout.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0};
		gridBagLayout.columnWeights = new double[]{1.0, 1.0, 1.0, 1.0, 1.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		siamInformation = new SiamInformation();
		siamInformation.setBackground(Color.YELLOW);
		GridBagConstraints gridBadContraintesSiamInformation = new GridBagConstraints();
		gridBadContraintesSiamInformation.gridwidth = 5;
		gridBadContraintesSiamInformation.insets = new Insets(0, 0, 5, 0);
		gridBadContraintesSiamInformation.gridx = 0;
		gridBadContraintesSiamInformation.gridy = 0;
		add(siamInformation, gridBadContraintesSiamInformation);
		
		forcePanel = new ForcePanel();
		GridBagConstraints gridBadConstraintsForcePanel = new GridBagConstraints();
		gridBadConstraintsForcePanel.gridwidth = 3;
		gridBadConstraintsForcePanel.insets = new Insets(0, 0, 0, 5);
		gridBadConstraintsForcePanel.fill = GridBagConstraints.BOTH;
		gridBadConstraintsForcePanel.gridx = 1;
		gridBadConstraintsForcePanel.gridy = 6;
		add(forcePanel, gridBadConstraintsForcePanel);
	}
	/**
	 * Construction board at the begining
	 */
	private void init() {
		for (int i=0;i<NUMBER_PIECES;i++){
			for (int j=0;j<NUMBER_PIECES;j++){
				SiamCase currentCase=new SiamCase(i,j);
				
				GridBagConstraints gbc_siamCasee = new GridBagConstraints();
				gbc_siamCasee.fill = GridBagConstraints.BOTH;
				gbc_siamCasee.gridx = j;
				gbc_siamCasee.gridy = i+1;
				add(currentCase, gbc_siamCasee);
				board[i][j]= currentCase;
			}
		}
		//ajout des rochers
		board[2][1].put(new Rocher());
		board[2][2].put(new Rocher());
		board[2][3].put(new Rocher());
		
		repaint();
	
	}
	/**
	 * 
	 * @param i row
	 * @param j column
	 * @return the siam case at (i,j)
	 */
	public SiamCase getCase(int i , int j){
		return this.board[i][j];
	}
	
	public SiamInformation getSiamInformation() {
		return siamInformation;
	}
	
	public ForcePanel getForcePanel() {
		return forcePanel;
	}
	public int getNUMBER_PIECES() {
		return NUMBER_PIECES;
	}
	
}
